<%--
  Created by IntelliJ IDEA.
  User: kuankuan
  Date: 2023/3/7
  Time: 9:59
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<html>
<head>
    <title>Title</title>
    <link rel="stylesheet" href="/css/bootstrap.min.css">
    <link rel="stylesheet" href="/css/bootstrap-theme.min.css">
    <script src="/js/jquery-1.12.4.min.js"></script>
    <script src="/js/bootstrap.min.js"></script>
    <style>
        body {
            background: none repeat scroll 0 0 #D8EDFC;
            margin: 0;
            padding: 0;
        }
        .page{
            margin: 20px;
        }
        .page a{
            text-decoration: none;
            padding: 5px 10px;
            cursor: pointer;
        }

        .page a:hover{
            background-color: cornflowerblue;
        }

        .page .active{
            background-color: palevioletred;
        }

    </style>
</head>

<body>

<table width="600" align="center"  class="table table-striped table table-bordered">
    <caption>餐桌</caption>
    <thead>
    <th>table_id</th>
    <th>table_name</th>
    <th>table_status</th>
    <th>reservation_time</th>
    <th width="200">操作</th>
    </thead>
    <tbody>
    <c:forEach var="dinner_table" items="${requestScope.pageBean1.datas}">
        <tr>
            <td>${dinner_table.table_id}</td>
            <td>${dinner_table.table_name}</td>
            <c:choose>
                <c:when test="${dinner_table.table_status==1}">
                    <td>已被预订</td>
                </c:when>
                <c:when test="${dinner_table.table_status==2}">
                    <td>正在使用</td>
                </c:when>
                <c:otherwise>
                    <td>可预订</td>
                </c:otherwise>
            </c:choose>
            <td>${dinner_table.reservation_time}</td>
            <td>
                <a href="/dinner_table?action=update&table_id=${dinner_table.table_id}">更新</a>
                <a onclick="deleteUser('${dinner_table.table_name}', ${dinner_table.table_id})">删除</a>
                <a onclick="UpdateUser1('${dinner_table.table_name}', ${dinner_table.table_id})">
                    <c:choose>
                        <c:when test="${dinner_table.table_status==0}">
                        </c:when>
                        <c:when test="${dinner_table.table_status==1}">
                            取消预约
                        </c:when>
                        <c:otherwise>
                            设为空闲
                        </c:otherwise>
                    </c:choose>
                </a>
            </td>
        </tr>
    </c:forEach>
    <tr>
        <td colspan="5" align="center"><a href="dinner_table?action=add">新增</a></td>
    </tr>
    </tbody>

</table>
<script>
    function deleteUser(name, id){
        if(confirm('是否确认删除'+name+"?")) {
            open('/dinner_table?action=delete&table_id='+id,'_self')
        }
    }
    function UpdateUser1(name, id){
        if(confirm('是否设为空闲'+name+"?")) {
            alert("设置成功")
            open('/dinner_table?action=update1&table_status=0&table_id='+id,'_self')
        }
    }

    onload = function () {
        if('${sessionScope.delMsg}' !== ''){
            alert('${sessionScope.delMsg}')
            fetch("/dinner_table?action=delMsg");
        }
    }
</script>
</body>
</html>
